﻿using System.Linq;
using NHDay_Linq.Domain;
using NHibernate;
using NHibernate.Linq;
using NUnit.Framework;

namespace NHDay_Linq
{
	[TestFixture]
	public class T08_LinqFuture : TestBase
	{
		[Test]
		public void Future()
		{
			using (ISession session = SessionFactory.OpenSession())
            using (ITransaction tx = session.BeginTransaction())
            {
				var adults = session.Query<Adult>().ToList();
				var children = session.Query<Child>().ToList();

				Assert.IsNotNull(adults);
				Assert.IsNotNull(children);
			}

			using (ISession session = SessionFactory.OpenSession())
			using (ITransaction tx = session.BeginTransaction())
			{
				session.Clear();
				var adults = session.Query<Adult>().ToFuture();
				var children = session.Query<Child>().ToFuture();

				 tx.Commit();

				Assert.Greater(adults.Count(), 0);
				Assert.Greater(children.Count(), 0);
			}
		}
	}
}
